import java.util.HashSet;
import java.util.Set;

/**
 * @author yexiebao
 * @date 2025/5/18
 */
public class Intersection {
    public static int[] getIntersection(int[] arr1, int[] arr2) {
      if(arr1.length==0||arr2.length==0){
          return new int[0];
      }
      Set<Integer> set = new HashSet<>();
      for(int i : arr1){
          set.add(i);
      }
      Set<Integer> resultSet = new HashSet<>();
      for(int i : arr2){
          if(set.contains(i)){
              resultSet.add(i);
          }
      }
      int[] result = new int[resultSet.size()];
      int i = 0;
      for(int j : resultSet){
          result[i++] = j;
      }
      return result;
    }
}